import 'package:boss/models/store_area.dart';
import 'package:boss/provider/table_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/sortList/sort_item_data.dart';
import 'package:boss/ui/widget/sortList/sort_list.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class AreaSortBrowser extends StatefulWidget {
  @override
  _AreaSortBrowserState createState() => _AreaSortBrowserState();
}

class _AreaSortBrowserState extends State<AreaSortBrowser> {
  List<SortItemData<StoreArea>> items;

  @override
  void initState() {
    super.initState();

    var tableProvider = Provider.of<TableProvider>(context, listen: false);
    items = tableProvider.storeAreas
        .map((item) => SortItemData(title: item.areaName, value: item))
        .toList();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: SortList(
            items: items,
          ),
        ),
        FixedBottomBtn(
          title: '保 存',
          onTap: () async {
            var tableProvider = Provider.of<TableProvider>(
              context,
              listen: false,
            );
            tableProvider.sortArea(items);
          },
        ),
      ],
    );
  }
}
